package com.java.controller;

import com.github.pagehelper.PageInfo;
import com.java.model.Advertiser;
import com.java.model.Apply;
import com.java.model.Finance;
import com.java.model.Result;
import com.java.service.AdvertiserService;
import com.java.service.LaunchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/advertiser")
public class AdvertiserController {

    @Autowired
    private AdvertiserService advertiserService;

    @Autowired
    private LaunchService launchService;

    @RequestMapping("/advertiserList")
    public String advertiserList(){
        return "/admin/Advertiser/list";
    }

    /*媒体组管理投放的申请单*/
    @RequestMapping("/launch/list")
    @ResponseBody
    public Result list(int adsId){
        Apply apply = new Apply();
        apply.setAdsId(adsId);
        PageInfo<Apply> pageInfo = advertiserService.applyList(apply);
        return Result.success(pageInfo.getList(),pageInfo.getTotal());
    }

    /*已投放*/
    @RequestMapping("/launch/put")
    @ResponseBody
    public Result put(int adsId){
        Apply apply = new Apply();
        apply.setAdsId(adsId);
        PageInfo<Apply> pageInfo = advertiserService.putList(apply);
        return Result.success(pageInfo.getList(),pageInfo.getTotal());
    }

    /*已完成*/
    @RequestMapping("/launch/performance")
    @ResponseBody
    public Result performance(int adsId){
        Apply apply = new Apply();
        apply.setAdsId(adsId);
        PageInfo<Apply> pageInfo = advertiserService.performanceList(apply);
        return Result.success(pageInfo.getList(),pageInfo.getTotal());
    }
    /*广告主拒绝验收*/
    @RequestMapping("/no")
    @ResponseBody
    public Result no2(Apply apply) {
        apply.setStatus(7);
        return launchService.yes(apply);
    }

    /*广告主验收成功*/
    @RequestMapping("/yes")
    @ResponseBody
    public Result yes(Apply apply) {
        apply.setStatus(8);
        return advertiserService.yes(apply);
    }
    @RequestMapping("/list")
    @ResponseBody
    public Result list(Advertiser advertiser){
        PageInfo<Advertiser> pageInfo = advertiserService.list(advertiser);
        return Result.success(pageInfo.getList(),pageInfo.getTotal());
    }


    @RequestMapping("/detail")
    public String detail(Model model, int id){
        Advertiser advertiser = advertiserService.get(id);
        model.addAttribute(advertiser);
        return "/admin/Advertiser/detail";
    }

    @RequestMapping("/remove")
    @ResponseBody
    public Result remove(int[] ids){
        advertiserService.remove(ids);
        return Result.success();
    }

    @RequestMapping("/financeList")
    public String financeList(){
        return "/admin/Advertiser/fList";
    }

    @RequestMapping("/fList")
    @ResponseBody
    public Result fList(Finance finance){
        PageInfo<Finance> pageInfo = advertiserService.fList(finance);
        return Result.success(pageInfo.getList(),pageInfo.getTotal());
    }

    @RequestMapping("/fDetail")
    public String fDetail(Model model, int id){
        Advertiser advertiser = advertiserService.get(id);
        model.addAttribute(advertiser);
        return "/admin/Advertiser/fDetail";
    }

}
